package com.example.controller;

import com.example.common.Result;
import com.example.entity.VideoHistory;
import com.example.entity.VideoLike;
import com.example.service.VideoLikeService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 视频收藏前端接口
 */
@RestController
@RequestMapping("/videoLike")
public class VideoLikeController {

    @Resource
    private VideoLikeService videoLikeService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody VideoLike videoLike) {
        videoLikeService.add(videoLike);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        videoLikeService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        videoLikeService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody VideoLike videoLike) {
        videoLikeService.updateById(videoLike);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        VideoLike videoLike = videoLikeService.selectById(id);
        return Result.success(videoLike);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(VideoLike videoLike ) {
        List<VideoLike> videoLikeList = videoLikeService.selectAll(videoLike);
        return Result.success(videoLikeList);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(VideoLike videoLike,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<VideoLike> pageInfo = videoLikeService.selectPage(videoLike, pageNum, pageSize);
        return Result.success(pageInfo);
    }

}
